package cn.com.lightech.led_g5g.presenter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import java.util.List;

import cn.com.lightech.led_g5g.biz.LedChannelBiz;
import cn.com.lightech.led_g5g.entity.DeviceGroup;
import cn.com.lightech.led_g5g.gloabal.Const;
import cn.com.lightech.led_g5g.gloabal.LedChannel;
import cn.com.lightech.led_g5g.view.device.IMainDeviceView;
import cn.com.lightech.led_g5g.view.device.impl.AddDeviceActivity;
import cn.com.lightech.led_g5g.view.device.impl.EditGroupActivity;
import cn.com.lightech.led_g5g.view.device.impl.HelpActivity;
import cn.com.lightech.led_g5g.wedgit.LedChannelNoDialog;
import cn.com.u2be.xbase.net.IUdp;
import cn.com.u2be.xbase.net.UDPManager;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by 明 on 2016/4/11.
 */
public class MainPresenter {

    private final Context mContext;
    private IMainDeviceView mainDeviceView;
    private LedChannelBiz chanelbiz = new LedChannelBiz();

    public MainPresenter(Context context, IMainDeviceView mainDeviceView) {
        this.mainDeviceView = mainDeviceView;
        this.mContext = context;
    }


    public void addGroup(List<DeviceGroup> deviceGroups) {
        Intent intent = new Intent();
        intent.setClass(mContext, EditGroupActivity.class);
        intent.putExtra(EditGroupActivity.ARGS_DEFAULT_DEVICE_GROUP, deviceGroups.get(0));
        intent.putExtra(EditGroupActivity.ARGS_NEW_GROUP_NUMBER, deviceGroups.get(deviceGroups.size() - 1).getNumber() + 1);
        mContext.startActivity(intent);
    }

    public void deleteDevice() {
        mainDeviceView.gotoDeleteDeviceFragment();
    }

    public void addNewDevice() {
        Intent intent = new Intent();
        intent.setClass(mContext, AddDeviceActivity.class);
        mContext.startActivity(intent);

    }


    public void deleteGroup() {
        mainDeviceView.gotoDeleteGroupFragment();
    }

    public void showHelp() {
        Intent intent = new Intent();
        intent.setClass(mContext, HelpActivity.class);
        mContext.startActivity(intent);
    }

    /**
     * 加载灯的通道信息
     */
    public void loadChanel() {
        Const.getInstance().setLedChannel(chanelbiz.getChannel());
    }



    /**
     * 设置灯的通道信息
     */
    public void setChannel(int ledChannel) {
        LedChannelBiz chanelbiz = new LedChannelBiz();
        chanelbiz.setChannel(ledChannel);
        Const.getInstance().setLedChannel(chanelbiz.getChannel());
    }


    public void showChangeChannelDialog() {
        final LedChannelNoDialog dialog = new LedChannelNoDialog(mContext);
        dialog.setOnButtonClickListener(new LedChannelNoDialog.OnButtonClickListener() {
            @Override
            public void onThreeButtonClick() {
                setChannel(LedChannel.Channel_A);
                dialog.dismiss();

            }

            @Override
            public void onFiveButtonClick() {
                setChannel(LedChannel.Channel_B);
                dialog.dismiss();
            }
        });
        dialog.show();

    }

}
